/*
 * @Descripttion: 文件说明
 * @version: V1.0
 * @Author: GW
 * @Date: 2021-07-29 10:40:42
 * @LastEditors: GW
 * @LastEditTime: 2021-09-08 15:58:32
 */
/**
 * 向后端请求用户的菜单，动态生成路由
 */
import { constantRouterMap } from "@/config/router.config";
import { generatorDynamicRouter } from "@/router/generator-routers";

const permission = {
  state: {
    whiteList: ["login", "register", "forgetPwd", "userEntry","activity"],//站外可访问的路由
    routers: constantRouterMap,
    addRouters: []
  },
  mutations: {
    SET_ROUTERS: (state, routers) => {
      state.addRouters = routers;
      state.routers = constantRouterMap.concat(routers);
    }
  },
  actions: {
    GenerateRoutes({ commit }, data) {
      return new Promise(resolve => {
        const { token } = data;
        generatorDynamicRouter(token).then(routers => {
          commit("SET_ROUTERS", routers);
          resolve();
        });
      });
    }
  }
};

export default permission;
